package com.template.templateuser.domain.service;

import com.template.templateuser.domain.dto.SysRoleDTO;
import com.template.templateuser.domain.mapper.SysRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class SysRoleServiceImpl implements SysRoleService {


    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public int saveSysRole(SysRoleDTO sysRoleDTO) {
        return sysRoleMapper.save(sysRoleDTO);
    }

    @Override
    public int updateSysRole(Long id, SysRoleDTO sysRoleDTO) {
        sysRoleDTO.setId(id);
        return sysRoleMapper.updateById(sysRoleDTO);
    }

    @Override
    public SysRoleDTO querySysRole(Long id) {
        return sysRoleMapper.findSysRoleById(id);
    }

    @Override
    public int deleteSysRole(Long id) {
        SysRoleDTO sysRoleDTO=new SysRoleDTO();
        sysRoleDTO.setId(id);
        return sysRoleMapper.updateById(sysRoleDTO);
    }

    @Override
    public int saveMenuRole(Long id, Set<Long> menuIds) {
        sysRoleMapper.deleteMenuRole(id);
        return sysRoleMapper.saveMenuRole(id,menuIds);
    }

    @Override
    public int saveRoleDept(Long id, Set<Long> deptIds) {
        sysRoleMapper.deleteSaveRoleDept(id);
        return sysRoleMapper.saveRoleDept(id,deptIds);
    }

    @Override
    public int saveUserRole(Long id, Set<Long> roleIds) {
        sysRoleMapper.deleteSaveUserRole(id);
        return sysRoleMapper.saveUserRole(id,roleIds);
    }

    @Override
    public List<String> getUserRolekeyList(Long userId) {
        if(userId == null){
            return new ArrayList<>();
        }
        return sysRoleMapper.getUserRolekeyList(userId);
    }

    @Override
    public List<String> getUserMenukeyList(Long userId) {
        if(userId == null){
            return new ArrayList<>();
        }
        return sysRoleMapper.getUserMenukeyList(userId);
    }
}
